/* $Id:edit_game.h jjs $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/
#ifndef EDIT_GAME_H
#define EDIT_GAME_H

#include <gtkmm.h>
#include <libglademm.h>
#include "list_games.h"
#include "edit_party.h"
#include "../general/channel.h"

/// Screen to edit game data

class edit_game : public Gtk::Window {
  public:
	edit_game(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> refGlade); ///< window
	virtual ~edit_game();   ///< remove window data
	void load(long gamenr); ///< Read data of a game
	void save();            ///< Save data again
	sigc::signal<void> signal_changed; ///< Signal to trigger when the game is edited
  private:
    std::string session;
  protected:
	int game_nr;
	Glib::RefPtr<Gnome::Glade::Xml> glade;
	Gtk::Entry* name;
	Gtk::TextView* description;
	Glib::RefPtr<Gtk::TextBuffer> desc_buffer;
	Gtk::ComboBox* join;
	Gtk::ComboBox* goal;
	Gtk::Entry* map_name;
	Gtk::Entry* game_url;
	Gtk::TreeView* party_list;
	Glib::RefPtr<Gtk::ListStore> party_store;
	Glib::RefPtr<Gtk::ListStore> join_store;
	Glib::RefPtr<Gtk::ListStore> goal_store;
	edit_party *party_window;
	vector<party> party_data;
	virtual void clicked_party(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
	virtual void party_changed();

	Gtk::Button* cancel_game;
	virtual void clicked_cancel();
	Gtk::Button* add_party;
	virtual void clicked_add_party();
	Gtk::Button* create_game;
	Gtk::Label* create_label;
	virtual void clicked_create();
	Gtk::Button* game_editor;
	virtual void clicked_editor();
	void clear_data();
	virtual void session_handler(channel *ch);

    class ComboColumns : public Gtk::TreeModelColumnRecord {
	  public:
    	Gtk::TreeModelColumn<Glib::ustring> text;
    	ComboColumns() {
			add(text);
		}
    };
	const ComboColumns ccols;

	class ModelColumns : public Gtk::TreeModelColumnRecord {
	  public:
    	Gtk::TreeModelColumn<Glib::ustring> name;
    	Gtk::TreeModelColumn<Glib::ustring> description;
    	Gtk::TreeModelColumn<int> party_nr;
    	ModelColumns() {
			add(name);
			add(description);
			add(party_nr);
		}
	};
	const ModelColumns cols;
};

#endif //EDIT_GAME_H
